
package br.gen.seam.gui;

import br.gen.seam.util.entity.Table;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Diego Araujo | diegogomesaraujo@gmail.com
 * @version 1.0
 */
public class SelectTablesModel extends DefaultTableModel {

    private ArrayList<Object[]> listTables = new ArrayList<Object[]>();

    private String[] nameColumns = new String[] {"Selection", "Schema", "Table"};

    public void setTables(List<Table> tables) {
        if(tables == null)
            return;
        for(Table table : tables) {
            listTables.add(new Object[] {
                new Boolean(false), table.getSchema(), table
            });
        }
    }

    @Override
    public String getColumnName(int coluna) {
        return nameColumns[coluna];
    }

    @Override
    public int getColumnCount() {
        return nameColumns.length;
    }

    @Override
    public int getRowCount() {
        if(listTables == null)
            return 0;
        return listTables.size();
    }

    @Override
    public Object getValueAt(int linha, int coluna) {
        return ((Object[]) listTables.get(linha))[coluna];
    }

    @Override
    public void setValueAt(Object aValue, int row, int column) {
        Object[] line = listTables.get(row);
        if(column == 0)
            line[column] = (Boolean) aValue;
        else
            line[column] = (String) aValue;
        listTables.set(row, line);
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if(columnIndex == 0)
            return Boolean.class;
        else
            return String.class;
    }
}